#!/bin/bash

PW_THRESHOLD=50
INTERVAL=10

function miner_offline()
{
    POWER=$(nvidia-smi -q -d POWER | awk '/Power Draw/ {print $4}')
    echo "$POWER < ${PW_THRESHOLD}" | bc
}

function msg()
{
    echo "$(date "+%F %T") : $1"
}

while true
do
    r=$(miner_offline)
    if [ "$r" -eq 1 ]; then
        msg "miner is offline, i will restart it"
        supervisorctl restart miner
	sleep 10
    else
        msg "miner is working, good job!"
    fi
    sleep ${INTERVAL}
done
